package everydayone.gcdofstring;
/**
 * @Date 2020/03/12
 * @author 王光浩
 * @Thinking 使用暴力法
 */
public class MethodTwo {
	public String gcdOfStrings(String str1, String str2) {
		int min=Math.min(str1.length(), str2.length());
		for(int i=min;i>0;i--) {
			if(str1.length()%i==0 && str2.length()%i==0) {
				if(judge(str1.substring(0,i),str1) && judge(str1.substring(0,i),str2))
					return str1.substring(0,i);
			}
		}
		return "";
	}
	private boolean judge(String t,String str) {
		int count=str.length()/t.length();
		StringBuilder re=new StringBuilder();
		for(int i=0;i<count;i++)
			re.append(t);
		return re.toString().equals(str);
	}
}
